using System.Collections.Generic;
using System.Text.RegularExpressions;
using Machine.Specifications;
using RxHeat.Common;

namespace RxHeat.Tests.Tracing
{
    [Behaviors]
    public class B_output_matches_stream_values_specification
    {
        protected static List<string> _onNextValues;
        protected static List<string> _output;

        private It output_should_not_be_empty = () => _output.Count.ShouldBeGreaterThan(0);

        private It trace_output_should_have_more_values_than_the_count_of_OnNext_values =
            () => _output.Count.ShouldBeGreaterThan(_onNextValues.Count);

        private It trace_output_should_have_the_exact_OnNext_values = () =>
            {
                var _matchIndex = new List<int>();

                _onNextValues.ForEach((onNextValue) =>
                    {
                        string find = _output.Find(o => Regex.IsMatch(o, onNextValue));
                        find.ShouldNotBeEmpty();
                        find.ShouldNotBeNull();
                    });
            };

        private It trace_output_should_have_the_same_order_of_OnNext_values = () =>
            {
                var _matchIndex = new List<int>();

                _onNextValues.ForEachI((i, onNextValue) =>
                    {
                        int foundIndex = _output.FindIndex(o => Regex.IsMatch(o, (string) onNextValue));
                        _matchIndex.Add(foundIndex);
                    });

                _matchIndex.ForEachI(i =>
                    {
                        if (i > 0)
                            _matchIndex[i].ShouldBeGreaterThan(_matchIndex[i - 1]);
                    });
            };
    }
}